﻿'Daryl Gonzalez & Andrew Dixon
'02/16/12
'Grading Category Sample


'TO DO: Needs add a category functionality and clean up code to enhance functionality and readibility.

Public Class Form1
    'progress bar possible using timer moving until x interval is reches = to percentage

    'Declare Global Variables to be used in modifying grade worth and amount.
    Dim gradeworthA As Double
    Dim gradeamountA As Integer
    Dim gradecatA As String
    Dim gradeworthB As Double
    Dim gradeamountB As Integer
    Dim gradecatB As String
    Dim percentcheck As Double = 100.0

    'Handles editing and saving attributes for the first grading category.
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        'change textboxes to labels for name
        If Button1.Text = "save" Then
            MsgBox("The " & gradecatA & " Category is worth " & gradeworthA & "% of the overall grade.")
            MsgBox("The " & gradecatA & " Category has " & gradeamountA & " item(s) for grading.")
            TextBox1.Enabled = False
            TextBox2.Enabled = False
            TextBox5.Enabled = False
            Button1.Text = "edit"
        ElseIf Button1.Text = "edit" Then
            TextBox1.Enabled = True
            TextBox2.Enabled = True
            TextBox5.Enabled = True
            Button1.Text = "save"
        End If
    End Sub

    'Handles editing and saving attributes for the second grading category.
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        'change textboxes to labels for name
        If Button2.Text = "save" Then
            MsgBox("The " & gradecatB & " Category is worth " & gradeworthB & "% of the overall grade.")
            MsgBox("The " & gradecatB & " Category has " & gradeamountB & " item(s) for grading.")
            TextBox3.Enabled = False
            TextBox4.Enabled = False
            TextBox6.Enabled = False
            Button2.Text = "edit"
        ElseIf Button2.Text = "edit" Then
            TextBox3.Enabled = True
            TextBox4.Enabled = True
            TextBox6.Enabled = True
            Button2.Text = "save"
        End If
    End Sub

    'Checks to see if a value is stored in a textbox.
    Private Function IsNotNothing(ByVal userinput As String) As Boolean
        If userinput = "" Then
            MsgBox("You are missing input in this area. Please add a value.")
            Return False
        Else
            Return True
        End If
    End Function

    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        'adding new object layout similar to others
        totalegradepercent(gradeworthA, gradeworthB)
        'move add layout to next area
    End Sub

    'When the user changes the percentage worth in the first category, save the textbox value to a variable.
    Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
        If IsNotNothing(TextBox1.Text) = True Then
            gradeworthA = CDbl(TextBox1.Text)
        End If
    End Sub

    'When the user changes the amount of items in the first category, save the textbox value to a variable.
    Private Sub TextBox2_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox2.TextChanged
        If IsNotNothing(TextBox2.Text) = True Then
            gradeamountA = CInt(TextBox2.Text)
        End If
    End Sub

    'When the user changes the name of the first category, save the textbox value to a variable.
    Private Sub TextBox5_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox5.TextChanged
        If IsNotNothing(TextBox5.Text) = True Then
            gradecatA = TextBox5.Text
        End If
    End Sub

    'When the user changes the percentage worth in the second category, save the textbox value to a variable.
    Private Sub TextBox3_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox3.TextChanged
        If IsNotNothing(TextBox3.Text) = True Then
            gradeworthB = CDbl(TextBox3.Text)
        End If
    End Sub

    'When the user changes the amount of items in the second category, save the textbox value to a variable.
    Private Sub TextBox4_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox4.TextChanged
        If IsNotNothing(TextBox4.Text) = True Then
            gradeamountB = CInt(TextBox4.Text)
        End If
    End Sub

    'When the user changes the name of the second category, save the textbox value to a variable.
    Private Sub TextBox6_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox6.TextChanged
        If IsNotNothing(TextBox6.Text) = True Then
            gradecatB = TextBox6.Text
        End If
    End Sub

    'Method to add up and check grading worth of all categories.
    Public Sub totalegradepercent(ByVal firstgradeworth As Double, ByVal secondgradeworth As Double)
        Dim worth As Double = (firstgradeworth + secondgradeworth)
        Dim percentremaining As Double

        If (worth >= percentcheck) Then
            MsgBox("The current grade percentage exceeds 100% of grading. Please adjust the grading categories.")
        Else
            percentremaining = (percentcheck - worth)
            MessageBox.Show("Your categories currently account for " & worth & "% of the total grading value.")
        End If
    End Sub

End Class
